package com.itheima.server.controller;

import com.itheima.model.vo.PageResult;
import com.itheima.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;
    /*评论-提交*/
    @PostMapping
    public ResponseEntity comments(@RequestBody Map map){
        String movementId = (String)map.get("movementId");
        String comment = (String)map.get("comment");
        commentsService.saveComments(movementId,comment);
        return ResponseEntity.ok(null);
    }
    /*评论列表*/
    @GetMapping
    public ResponseEntity recommend(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize,String movementId){
        PageResult pageResult=commentsService.findComments(movementId,page, pagesize);
        return ResponseEntity.ok(pageResult);
    }
    /**
     * 评论点赞
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String commentId) {
        //1.调用service处理
        Integer likeCount = commentsService.likeCount(commentId);
        return ResponseEntity.ok(likeCount);
    }

    /*    *
     * 取消评论点赞*/
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String commentId) {
        //1.调用service处理
        Integer likeCount = commentsService.dislikeCount(commentId);
        return ResponseEntity.ok(likeCount);
    }

}
